{include file='header'/}
<body class="pear-admin">
<form class="layui-form" action="<?php echo url('admin/edit'); ?>" method="post">
    <div class="mainBox">
        <div class="main-container layui-container">
            <div class="layui-form-item hui-home-show" style="margin-top:20px">
                <div class="avatar hui-upload-avatar">
                    <i></i>
                    <input type="hidden" value="<?php echo $data['avatar']; ?>" name="avatar"
                           class="layui-input layui-input-disabled"
                           id="avatar">
                    <img src="<?php echo $data['avatar']; ?>">
                    <div class="cover">点击编辑</div>
                </div>
                <div class="username"><?php echo $data['username']; ?></div>
                <div class="email"><?php echo $data['email']; ?></div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">登录账户</label>
                <div class="layui-input-block">
                    <input type="text" name="username" class="layui-input readonly_bg" readonly=""
                           value="<?php echo $data['username']; ?>">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">昵称</label>
                <div class="layui-input-block">
                    <input type="text" name="nickname" class="layui-input " value="<?php echo $data['nickname']; ?>"
                           lay-verify="required">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">用户email</label>
                <div class="layui-input-block">
                    <input type="text" name="email" class="layui-input" lay-reqtext="请输入email"
                           placeholder="请输入email" value="<?php echo $data['email']; ?>" lay-verify="email">
                </div>
                <tip>填写邮箱。</tip>
            </div>

        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <input type="hidden" name="id" value="<?php echo $data['id'] ?>">
            <input type="hidden" name="status" value="<?php echo $data['status'] ?>">
            <input type="hidden" name="role_id" value="<?php echo $data['role_id'] ?>">
            <input type="hidden" name="type" value="edit_user_info">
            <input type="hidden" name="__token__" value="{:token()}"/>
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="doSub">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>

{include file='footer'/}
<script>
  layui.use(['upload', 'jquery', 'table', 'form'], function () {
    var layuiUpload = layui.upload, $ = layui.jquery, form = layui.form;
    var table = layui.table;
    var __token__ = $("input[name='__token__']").val();

    layuiUpload.render({
      elem: '.hui-upload-avatar',
      url: GV.image_upload_url,
      data: {
        __token__: __token__
      },
      before: function (obj) {
        obj.preview(function (index, file, result) {

        });
      },
      done: function (res) {
        //layer.msg('上传成功');
        $('.hui-upload-avatar img').attr('src', res.url);
        $('#avatar').val(res.url);
        let admin_id = "<?php echo $data['id']; ?>";
        //修改头像
        $.post("<?php echo url('admin/edit'); ?>", {id: admin_id, avatar: res.url, __token__: __token__}, function (res) {
          if (res.code === 1 || res.code === 200) {
            layer.msg(res.msg, {icon: 1, time: 1200});
          } else {
            layer.msg(res.msg, {icon: 2, time: 1200});
          }
        });
      }
    });

  });
</script>
